﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;

namespace G.Controls
{
    /// <summary>
    /// 从右边弹出的窗口，和系统设置保持一致
    /// </summary>
    public class FlyoutPopup : G.Controls.ChildWindow
    {
        public static DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(string), typeof(FlyoutPopup), new PropertyMetadata(null));
        public string Header
        {
            get { return this.GetValue(HeaderProperty) as string; }
            set { this.SetValue(HeaderProperty, value); }
        }

        public static DependencyProperty HeaderBrushProperty = DependencyProperty.Register("HeaderBrush", typeof(Brush), typeof(FlyoutPopup), new PropertyMetadata(null));
        public object HeaderBrush
        {
            get { return (Brush)this.GetValue(HeaderBrushProperty); }
            set { this.SetValue(HeaderBrushProperty, value); }
        }


        public static DependencyProperty IsOpenSettingsPaneProperty = DependencyProperty.Register("IsOpenSettingsPane", typeof(bool), typeof(FlyoutPopup), new PropertyMetadata(true));
        public bool IsOpenSettingsPane
        {
            get { return (bool)this.GetValue(IsOpenSettingsPaneProperty); }
            set { this.SetValue(IsOpenSettingsPaneProperty, value); }
        }


        public static DependencyProperty ContentMarginProperty = DependencyProperty.Register("ContentMargin", typeof(Thickness), typeof(FlyoutPopup),null);
        public Thickness ContentMargin
        {
            get { return (Thickness)this.GetValue(ContentMarginProperty); }
            set { this.SetValue(ContentMarginProperty, value); }
        }

        #region 事件

        public event EventHandler Opened;

        /// <summary>
        /// 点击返还按钮时的关闭事件
        /// </summary>
        public event EventHandler BackClosed;
        #endregion

        #region 属性


        private Button backButton;


        #endregion

        protected override void OnOpening()
        {
            base.OnOpening();
            this.Height = Windows.UI.Xaml.Window.Current.Bounds.Height;
            this.Popup.IsLightDismissEnabled = true;
            this.Width = 480;
            this.HorizontalOffset = Windows.UI.Xaml.Window.Current.Bounds.Width - this.Width;
        }

        public FlyoutPopup()
        {
            this.DefaultStyleKey = typeof(FlyoutPopup);
        }
        protected override void OnOpened()
        {
            if (this.Opened != null)
            {
                this.Opened(this, new EventArgs());
            }
        }


        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.Transitions = new TransitionCollection();
            PaneThemeTransition transition = new PaneThemeTransition();
            //EntranceThemeTransition transition = new EntranceThemeTransition();
            //transition.FromHorizontalOffset = 100;
            this.Transitions.Add(transition);
        }
    }
}
